package com.xunyin.modules.meituanstoremap.rest;


import com.xunyin.annotation.AnonymousAccess;
import com.xunyin.dozer.service.IGenerator;
import com.xunyin.modules.log.Log;
import com.xunyin.modules.aop.ForbidSubmit;
import com.xunyin.modules.meituan.domain.TMeituanStoremap;
import com.xunyin.modules.meituan.param.MeituanParam;
import com.xunyin.modules.meituan.service.TMeituanStoremapService;
import com.xunyin.modules.meituan.service.dto.TMeituanStoremapQueryCriteria;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author xunyinyunshang  <3594419785@qq.com>
 * @date 2023-02-27
 */
@Api(tags = "共享空间:美团门店映射")
@RestController
@RequestMapping("api")
public class TMeituanStoremapController {

    private final TMeituanStoremapService tMeituanStoremapService;

    private final IGenerator generator;


    public TMeituanStoremapController(TMeituanStoremapService tMeituanStoremapService, IGenerator generator) {
        this.tMeituanStoremapService = tMeituanStoremapService;
        this.generator = generator;
    }

    @Log("查询美团门店映射")
    @ApiOperation(value = "查询美团门店映射")
    @GetMapping(value = "/tMeituanStoremap")
    @PreAuthorize("hasAnyRole('admin','MAINPART_ALL','MAINPART_SELECT')")
    public ResponseEntity geTMeituanStoremap(TMeituanStoremapQueryCriteria criteria, Pageable pageable) {
        Map<String, Object> queryAll = tMeituanStoremapService.queryAll(criteria, pageable);
        return new ResponseEntity<>(queryAll, HttpStatus.OK);
    }

    @ForbidSubmit
    @Log("新增美团门店映射")
    @ApiOperation(value = "新增美团门店映射")
    @PostMapping(value = "/tMeituanStoremap")
    @PreAuthorize("hasAnyRole('admin','YXSYSTEMUSERLEVEL_ALL','YXSYSTEMUSERLEVEL_CREATE')")
    public ResponseEntity create(@Validated @RequestBody TMeituanStoremap resources) {
        System.out.println("getEPoiId" + resources.getStoreId());
        System.out.println("getEPoiName" + resources.getStoreName());
        return new ResponseEntity<>(tMeituanStoremapService.save(resources), HttpStatus.CREATED);
    }

    @ForbidSubmit
    @Log("修改美团门店映射")
    @ApiOperation(value = "修改美团门店映射")
    @PutMapping(value = "/tMeituanStoremap")
    @PreAuthorize("hasAnyRole('admin','YXSYSTEMUSERLEVEL_ALL','YXSYSTEMUSERLEVEL_EDIT')")
    public ResponseEntity update(@Validated @RequestBody TMeituanStoremap resources) {
        System.out.println("getEPoiId" + resources.getStoreId());
        System.out.println("getEPoiName" + resources.getStoreName());
        tMeituanStoremapService.saveOrUpdate(resources);
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    }

    /**
     * 美团门店套餐映射
     *
     * @return
     */
    @GetMapping(value = "/data/getSetMealList")
    @AnonymousAccess
    public ResponseEntity getSetMealList(String dealStatus) {
        MeituanParam queryParam = new MeituanParam();
        queryParam.setDealStatus(Integer.parseInt(dealStatus));
        return new ResponseEntity<>(tMeituanStoremapService.getSetMealList(queryParam), HttpStatus.OK);
    }


}
